#include "Message.h"




Message::Message(int type, std::string id)
:	isReceived(false)
,	isNeedCloseConnection(false)
{
	m_data = new ByteArray();
	m_data->writeInt(type);
	m_data->writeUTF(id);
}

Message::~Message()
{
	delete m_data;
}

ByteArray* Message::getData()
{
	return m_data;
}

void Message::setData(ByteArray* data)
{
	if(m_data == NULL)
	{
		m_data = new ByteArray();
	}
	m_data->clear();
	m_data->writeBytes(data->readBytes(), data->length());
}

int Message::getType()
{
	m_data->seek(MSG_OFFSET_TYPE);

	return m_data->readInt();
}

std::string Message::getId()
{
	m_data->seek(MSG_OFFSET_ID);

	return m_data->readUTF();
}